home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Format (PL) 2008 December
/
PC_Format_122008.iso
/
Multimedia
/
MediaPortal 0.2.3.0
/
MediaPortal_0.2.3.0_Setup.exe
/
scripts
/
imdb
/
edb_co_il.csscript
next >
Wrap
Text File
|
2007-10-31
|
17KB
|
531 lines
//css_reference "core.dll";
//css_reference "Databases.dll";
//css_reference "utils.dll";
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Collections;
using System.Web;
using System.Text.RegularExpressions;
using MediaPortal.Util;
class Grabber : MediaPortal.Video.Database.IIMDBScriptGrabber
{
public Grabber()
{
}
void MediaPortal.Video.Database.IIMDBScriptGrabber.FindFilm(string strSearch, int iLimit, ArrayList elements)
{
int iCount = 0;
string strTitle;
try
{
string absoluteUri;
string strURL = "http://www.edb.co.il/Find.php?q=" + strSearch;
string strBody = GetPage(strURL, "windows-1255", out absoluteUri);
int iStartOfMovieList = strBody.IndexOf("כותרים נפוצים");
if (iStartOfMovieList < 0)
{
return;
}
int iEndOfMovieList = strBody.IndexOf("</div><br />", iStartOfMovieList);
if (iEndOfMovieList < 0)
{
iEndOfMovieList = strBody.Length;
}
strBody = strBody.Substring(iStartOfMovieList, iEndOfMovieList - iStartOfMovieList);
while ((true) && (iCount < iLimit))
{
////<A HREF="/Title?0167261">Lord of the Rings: The Two Towers, The (2002)</A>
int iAHREF = strBody.IndexOf("<a href=");
if (iAHREF >= 0)
{
int iEndAHREF = strBody.IndexOf("</a>");
if (iEndAHREF >= 0)
{
iAHREF += "<a href=.".Length;
string strAHRef = strBody.Substring(iAHREF, iEndAHREF - iAHREF);
int iURL = strAHRef.IndexOf(">");
if (iURL > 0)
{
strTitle = "";
strURL = strAHRef.Substring(0, iURL);
if (strURL[strURL.Length - 1] == '\'')
strURL = strURL.Substring(0, strURL.Length - 1);
iURL+="<span style='direction: rtl;'>".Length + 1;
int iURLEnd = strAHRef.IndexOf("</span>", iURL);
if (iURLEnd > 0)
{
strTitle = strAHRef.Substring(iURL, iURLEnd - iURL);
iURLEnd = strAHRef.IndexOf("(", iURLEnd);
if (iURLEnd > 0)
{
iURL = iURLEnd;
iURLEnd = strAHRef.IndexOf(")", iURLEnd);
if (iURLEnd > 0)
{
strTitle+= " " + strAHRef.Substring(iURL, iURLEnd - iURL + 1);
}
}
}
else
strTitle = strAHRef.Substring(iURL);
strURL = String.Format("http://www.edb.co.il{0}", strURL);
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
int endTagLength = "</a>".Length;
int posNextTag = strBody.IndexOf("<", iEndAHREF + endTagLength);
if (posNextTag > 0)
{
string strSub = strBody.Substring(iEndAHREF + endTagLength, posNextTag - (iEndAHREF + endTagLength));
strTitle += strSub;
}
// to avoid including of
if ((strTitle.IndexOf("\n") < 0) && (strTitle.IndexOf(" ") < 0))
{
MediaPortal.Video.Database.IMDB.IMDBUrl url = new MediaPortal.Video.Database.IMDB.IMDBUrl(strURL, strTitle + " - מתוך edb.co.il", "edb_co_il");
elements.Add(url);
}
iCount++;
}
if (iEndAHREF + 1 >= strBody.Length)
break;
iStartOfMovieList = iEndAHREF + 1;
strBody = strBody.Substring(iEndAHREF + 1);
}
else
{
break;
}
}
else
{
break;
}
}
}
catch (Exception ex)
{
MediaPortal.GUI.Library.Log.Error("exception for edb lookup of {0} err:{1} stack:{2}",strSearch, ex.Message, ex.StackTrace);
}
}
bool MediaPortal.Video.Database.IIMDBScriptGrabber.GetDetails(MediaPortal.Video.Database.IMDB.IMDBUrl url, ref MediaPortal.Video.Database.IMDBMovie movieDetails)
{
try
{
int iStart = 0;
int iEnd = 0;
movieDetails.Reset();
// add databaseinfo
// may add an another grabber
movieDetails.Database = "edb_co_il";
string strAbsURL;
string strBody = GetPage(url.URL, "windows-1255", out strAbsURL);
if (strBody == null || strBody.Length == 0)
return false;
// IMDBNumber
int iPos = strAbsURL.IndexOf("/titles/");
if (iPos > 0)
{
iPos += "/titles/".Length;
movieDetails.IMDBNumber = strAbsURL.Substring(iPos);
int pos = movieDetails.IMDBNumber.IndexOf("/");
if (pos > 0)
movieDetails.IMDBNumber = movieDetails.IMDBNumber.Substring(0, pos);
}
// Title
url.Title = url.Title.Trim();
iEnd = url.Title.IndexOf("(");
if (iEnd >= 0)
{
int yearEnd = url.Title.IndexOf(")");
if (yearEnd >= 0)
{
try
{
movieDetails.Year = int.Parse(url.Title.Substring(iEnd+1, yearEnd - iEnd - 1));
}
catch (Exception)
{
}
}
movieDetails.Title = url.Title.Substring(0, iEnd);
}
else
movieDetails.Title = url.Title;
string RegTitleBlock = "<p class='ph1_title'.*>(.*)</p>";
Match titleBlock = Regex.Match(strBody, RegTitleBlock);
if (titleBlock.Success)
{
// I used the MPARating string as a subtitle (because it appears in the mediaportal below the title)
movieDetails.MPARating = movieDetails.Title.Trim();
movieDetails.PlotOutline = movieDetails.Title.Trim();
movieDetails.Title = titleBlock.Groups[1].Value;
}
else
{
movieDetails.Title = movieDetails.Title.Trim();
movieDetails.PlotOutline = movieDetails.Title.Trim();
}
movieDetails.TagLine = "";
// Plot
String PLOT_START="<div class='fieldtitle'>עלילה</div>";
String PLOT_END="</div>";
int plotPos = strBody.IndexOf(PLOT_START);
if (plotPos >= 0)
{
plotPos+=PLOT_START.Length;
int plotEndPos = strBody.IndexOf(PLOT_END, plotPos);
if (plotEndPos >= 0)
{
movieDetails.Plot = strBody.Substring(plotPos, plotEndPos - plotPos).Trim().Replace("<div>","").Replace("<br />","\n").Replace("\\'","\"");
}
}
// Votes
String VOTE_REG = "alt='(\\d*) גולשים דירגו: (\\d\\.?\\d*) כוכבים' />";
Match voteBlock = Regex.Match(strBody, VOTE_REG);
if (voteBlock.Success)
{
movieDetails.Votes = voteBlock.Groups[1].Value;
try
{
movieDetails.Rating = float.Parse(voteBlock.Groups[2].Value);
}
catch (Exception ex2)
{
MediaPortal.GUI.Library.Log.Error("exception for edb lookup of {0} err:{1} stack:{2}", url.URL, ex2.Message, ex2.StackTrace);
}
}
// Runtime
String RUNTIME_REG= "<p><span class='fieldname'>זמן ריצה:</span> (\\d*) דקות.</p>";
Match runtimeBlock = Regex.Match(strBody, RUNTIME_REG);
if (runtimeBlock.Success)
{
try
{
movieDetails.RunTime = int.Parse(runtimeBlock.Groups[1].Value);
}
catch (Exception ex3)
{
MediaPortal.GUI.Library.Log.Error("exception for edb lookup of {0} err:{1} stack:{2}", url.URL, ex3.Message, ex3.StackTrace);
}
}
// Genres
String GENRE_START="<p><span class='fieldname'>ז'אנר:</span>";
String GENRE_INSTANCE_START="<a href='/movies/browse.php?genre=";
String GENRE_INSTANCE_END="'>";
String GENRE_END="</p>";
int genrePos = strBody.IndexOf(GENRE_START);
if (genrePos >= 0)
{
genrePos+=GENRE_START.Length;
int genreEndPos = strBody.IndexOf(GENRE_END, genrePos);
if (genreEndPos >= 0)
{
String genreString = strBody.Substring(genrePos, genreEndPos - genrePos + 1);
genrePos = genreString.IndexOf(GENRE_INSTANCE_START);
movieDetails.Genre = "";
while (genrePos >= 0)
{
genrePos+=GENRE_INSTANCE_START.Length;
genreEndPos = genreString.IndexOf(GENRE_INSTANCE_END, genrePos);
if (genreEndPos >= 0)
{
String genre = genreString.Substring(genrePos, genreEndPos - genrePos);
movieDetails.Genre+=genre;
}
genrePos = genreString.IndexOf(GENRE_INSTANCE_START, genrePos);
if (genrePos >= 0)
{
movieDetails.Genre+=" / ";
}
}
}
}
// Actors
String ACTOR_START="<div class='fieldtitle'>צוות שחקנים</div>";
String ACTOR_INSTANCE_START="<a href='/people/";
String ACTOR_INSTANCE_START2="/'>";
String ACTOR_INSTANCE_END="</a>";
String AS_START="....";
String AS_END="</td>";
String ACTOR_END="</table>";
int actorPos = strBody.IndexOf(ACTOR_START);
if (actorPos >= 0)
{
actorPos+=ACTOR_START.Length;
int actorEndPos = strBody.IndexOf(ACTOR_END, actorPos);
if (actorEndPos >= 0)
{
String actorString = strBody.Substring(actorPos, actorEndPos - actorPos + 1);
actorPos = actorString.IndexOf(ACTOR_INSTANCE_START);
movieDetails.Cast = "";
while (actorPos >= 0)
{
actorPos+=ACTOR_INSTANCE_START.Length;
actorPos = actorString.IndexOf(ACTOR_INSTANCE_START2, actorPos);
if (actorPos >= 0)
{
actorPos+=ACTOR_INSTANCE_START2.Length;
actorEndPos = actorString.IndexOf(ACTOR_INSTANCE_END, actorPos);
if (actorEndPos >= 0)
{
String actor = actorString.Substring(actorPos, actorEndPos - actorPos);
movieDetails.Cast+=actor;
int asPos = actorString.IndexOf(AS_START, actorPos);
if (asPos >= 0)
{
asPos+=AS_START.Length;
int asEndPos = actorString.IndexOf(AS_END, asPos);
if (asEndPos >= 0)
{
String asStr = actorString.Substring(asPos, asEndPos - asPos).Trim();
movieDetails.Cast+=" as "+asStr;
}
}
}
actorPos = actorString.IndexOf(ACTOR_INSTANCE_START, actorPos);
if (actorPos >= 0)
{
movieDetails.Cast+="\n";
}
}
}
}
}
// Director
String DIRECTOR_START="<div class='columnfields_right'>בימוי</div>";
String DIRECTOR_END="</div>";
int directorPos = strBody.IndexOf(DIRECTOR_START);
if (directorPos >= 0)
{
directorPos+=DIRECTOR_START.Length;
int directorEndPos = strBody.IndexOf(DIRECTOR_END, directorPos);
if (directorEndPos >= 0)
{
String directorLine = strBody.Substring(directorPos, directorEndPos - directorPos);
String DIRECTOR_REG= "<a href=\"/people/pp\\d*/\">(.*)</a>";
Match directorBlock = Regex.Match(directorLine, DIRECTOR_REG);
movieDetails.Director = "";
while (directorBlock.Success)
{
movieDetails.Director+= directorBlock.Groups[1].Value;
directorBlock = directorBlock.NextMatch();
if (directorBlock.Success)
{
movieDetails.Director+=", ";
}
}
}
}
// WritingCredits
String WRITER_START="<div class='columnfields_right'>תסריט</div>";
String WRITER_END="</div>";
int writerPos = strBody.IndexOf(WRITER_START);
if (writerPos >= 0)
{
writerPos+=WRITER_START.Length;
int writerEndPos = strBody.IndexOf(WRITER_END, writerPos);
if (writerEndPos >= 0)
{
String writerLine = strBody.Substring(writerPos, writerEndPos - writerPos);
String WRITER_REG= "<a href=\"/people/pp\\d*/\">(.*)</a>";
Match writerBlock = Regex.Match(writerLine, WRITER_REG);
movieDetails.WritingCredits = "";
while (writerBlock.Success)
{
movieDetails.WritingCredits+= writerBlock.Groups[1].Value;
writerBlock = writerBlock.NextMatch();
if (writerBlock.Success)
{
movieDetails.WritingCredits+=", ";
}
}
}
}
return true;
}
catch (Exception ex)
{
MediaPortal.GUI.Library.Log.Error("exception for edb lookup of {0} err:{1} stack:{2}", url.URL, ex.Message, ex.StackTrace);
}
return false;
}
string MediaPortal.Video.Database.IIMDBScriptGrabber.GetName()
{
return "EDB";
}
string MediaPortal.Video.Database.IIMDBScriptGrabber.GetLanguage()
{
return "Hebrew";
}
private string GetPage(string strURL, string strEncode, out string absoluteUri)
{
string strBody = "";
absoluteUri = String.Empty;
Stream ReceiveStream = null;
StreamReader sr = null;
WebResponse result = null;
try
{
// Make the Webrequest
//Log.Info("EDB: get page:{0}", strURL);
WebRequest req = WebRequest.Create(strURL);
result = req.GetResponse();
ReceiveStream = result.GetResponseStream();
// Encoding: depends on selected page
Encoding encode = System.Text.Encoding.GetEncoding(strEncode);
sr = new StreamReader(ReceiveStream, encode);
strBody = sr.ReadToEnd();
absoluteUri = result.ResponseUri.AbsoluteUri;
}
catch (Exception)
{
//Log.Error("Error retreiving WebPage: {0} Encoding:{1} err:{2} stack:{3}", strURL, strEncode, ex.Message, ex.StackTrace);
}
finally
{
if (sr != null)
{
try
{
sr.Close();
}
catch (Exception)
{
}
}
if (ReceiveStream != null)
{
try
{
ReceiveStream.Close();
}
catch (Exception)
{
}
}
if (result != null)
{
try
{
result.Close();
}
catch (Exception)
{
}
}
}
return strBody;
} // END GetPage()
string ParseAHREFIMDB(string strBody, int iahref, string strURL)
{
int iStart = strBody.IndexOf("<a href=\"", iahref);
if (iStart < 0)
iStart = strBody.IndexOf("<A HREF=\"", iahref);
if (iStart < 0)
return "";
int iEnd = strBody.IndexOf("</a>", iStart);
if (iEnd < 0)
iEnd = strBody.IndexOf("</A>", iStart);
if (iEnd < 0)
return "";
iStart += "<a href=\"".Length;
int iSep = strBody.IndexOf(">", iStart);
string strurl = strBody.Substring(iStart, (iSep - iStart) - 1);
iSep++;
string strTitle = strBody.Substring(iSep, iEnd - iSep);
strTitle = MediaPortal.Util.Utils.stripHTMLtags(strTitle);
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
strTitle = strTitle.Trim();
return strTitle.Trim();
}
string ParseGenresIMDB(string strBody, int iGenre, string url)
{
string strTmp;
string strTitle = "";
string strHRef = strBody.Substring(iGenre);
int iSlash = strHRef.IndexOf(" / ");
int iEnd = 0;
int iStart = 0;
if (iSlash >= 0)
{
int iRealEnd = strHRef.IndexOf(">more<");
if (iRealEnd < 0)
iRealEnd = strHRef.IndexOf("</div>");
while (iSlash < iRealEnd)
{
iStart = iEnd + 2;
iEnd = iSlash;
int iLen = iEnd - iStart;
if (iLen < 0)
break;
strTmp = strHRef.Substring(iStart, iLen);
strTitle = strTitle + ParseAHREFIMDB(strTmp, 0, "") + " / ";
iSlash = strHRef.IndexOf(" / ", iEnd + 2);
if (iSlash < 0)
iSlash = iRealEnd;
}
}
// last genre
iEnd += 2;
strTmp = strHRef.Substring(iEnd);
strTitle = strTitle + ParseAHREFIMDB(strTmp, 0, "");
HTMLUtil htmlUtil = new HTMLUtil();
htmlUtil.ConvertHTMLToAnsi(strTitle, out strTitle);
return strTitle;
}
}